package cn.joeg.dp.singleton.lazy;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by CQ on 2018/3/7.
 */
public class ReflectTest {

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        LazySingleton4 s1 = LazySingleton4.getInstance();
        //利用反射机制，来调用私有的构造方法，来创建一个实例
        Constructor<LazySingleton4> constructor = LazySingleton4.class.getDeclaredConstructor();
        //强制授权让他可以访问
        constructor.setAccessible(true);

        LazySingleton4 s2 = constructor.newInstance();
        System.out.println(s1 == s2);
    }
}
